package com.itheima.service;

import com.itheima.pojo.Account;
import com.itheima.pojo.ShowMovie;


import java.util.ArrayList;
import java.util.Scanner;

public class ManagerService {

    Scanner sc = new Scanner(System.in);
    Account account;
    UserManger u = new UserManger();
    MovieManger m = new MovieManger();

    /**
     * 1.后台管理端的操作页/主页方法
     *
     * @param account 登录成功的账户对象
     */
    public void start(Account account, ArrayList<Account> list,ArrayList<ShowMovie> showMovies) {
        //保证接收的用户对象为管理人员
        this.account = account;

        //1.1 重复进行功能选择
        while (true) {
            System.out.println("==================黑马影院后台管理==================");
            System.out.println("尊敬的管理员" + account.getUsername() + "，欢迎使用黑马影院后台管理系统！");
            System.out.println("请选择以下功能：\r\n1.电影管理\t2.用户管理\t3.个人信息\t4.退出");
            //1.2 使用Scanner录入选择
            String choice = sc.next();

            //1.3 根据选择的不同执行不同功能：switch分支结构
            switch (choice) {
                case "1" -> m.movieManagerStart(showMovies);
                case "2" -> u.userManagerStart(list);
                case "3" -> personalInformation();
                case "4" -> {
                    System.out.println("感谢您的使用，退出后台管理！");
                    return;
                }
                default -> System.out.println("您的选择有误，请检查后重试！");
            }
        }
    }

    /**
     * 2.个人信息展示
     */
    public void personalInformation() {
        while (true) {
            System.out.println("==========个人信息==========");
            //避免直接打印出null，使用三元运算符处理
            System.out.println("姓名：" + (account.getName() == null ? "" : account.getName()));
            System.out.println("性别：" + (account.getGender() == null ? "" : account.getGender()));
            System.out.println("年龄：" + account.getAge() + "岁");
            System.out.println("生日：" + (account.getBirthday() == null ? "" : account.getBirthday()));
            System.out.println("地址：" + (account.getAddress() == null ? "" : account.getAddress()));
            System.out.println("用户名：" + account.getUsername());
            System.out.println("密码：******");
            System.out.println("----------------------------");
            System.out.println("是否修改信息？1.是\t2.否");
            String choice = sc.next();
            if ("1".equals(choice)) {
                System.out.println("姓名");
                String next = sc.next();
                account.setGender(next);
                System.out.println("性别");
                int next1 = sc.nextInt();
                account.setAge(next1);
                System.out.println("年龄");
                String next2 = sc.next();
                account.setBirthday(next2);
                System.out.println("生日");
                String next3 = sc.next();
                account.setAddress(next3);
                System.out.println("地址");
                String next4 = sc.next();
                account.setName(next4);
                System.out.println("修改完成!");
                break;
            } else if ("2".equals(choice)) {
                //不修改信息，直接退出个人信息展示
                return;
            } else {
                System.out.println("您的选择有误，请重试！");
            }
        }
    }


}
